package com.ruoyi.fetv.controller.userController.comment;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.aspect.annotation.AutoDict;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fetv.controller.userController.comment.vo.RequestVO;
import com.ruoyi.fetv.controller.userController.comment.vo.RespVO;
import com.ruoyi.fetv.controller.vo.comment.AddReq;
import com.ruoyi.fetv.domain.FetvComment;
import com.ruoyi.fetv.service.IFetvCommentService;
import com.ruoyi.fetv.util.Constant;
import com.ruoyi.fetv.util.Convert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName CommentController
 * @Description 用户评论管理
 * @Author 肖润杰
 * @Time 2023/3/10 8:34
 * @Version 1.0
 */
@RestController
@Validated
@Api(value = "/v1/fetv/comment", tags = {"用户资讯评论"})
@RequestMapping("/v1/fetv/comment")
@AutoDict
public class CommentController extends BaseController {
    @Autowired
    private IFetvCommentService fetvCommentService;

    /**
     * 查询资讯评论列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataTypeClass = RequestVO.class, name = "UserCommentRequestVO", value = "资讯查询参数", required = true)
    })
    @ApiOperation(value = "查询资讯评论列表", notes = "查询资讯评论列表", httpMethod = "GET")
    @ApiResponse(code = 200, message = "", response = TableDataInfo.class)
    @GetMapping("/list")
    public TableDataInfo<List<RespVO>> list(RequestVO requestVO) {
        startPage();
        FetvComment fetvComment = (FetvComment) Convert.convert(requestVO, FetvComment.class);
        fetvComment.setAuditStatus(Long.valueOf(Constant.APPROVE));
        List<FetvComment> list = fetvCommentService.selectFetvCommentList(fetvComment);
        Convert.covertList(list, FetvComment.class, RespVO.class);
        return getDataTable(list);
    }


    /**
     * 新增资讯评论
     */

    @ApiOperation(value = "新增资讯评论", notes = "新增资讯评论", httpMethod = "POST")
    @Log(title = "资讯评论", businessType = BusinessType.INSERT)
    @ApiResponse(code = 200, message = "", response = int.class)
    @PostMapping
    public AjaxResult add(@ApiParam(name = "UserCommentAddVO", value = "资讯评论", required = true) @RequestBody @Valid AddReq fetvComment) {
        return toAjax(fetvCommentService.insertFetvComment(fetvComment));
    }

// TODO: 2023/3/10  点赞 ， 踩 ，【收藏】   由于没有看到用户登录的地方，点赞，踩 可以为ip区分，用户分区  也就没有写了，
}
